home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 35.6 KB | 1,282 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDemoDialogs.More.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UDEMODIALOGS__
- #include "UDemoDialogs.h"
- #endif
-
- // DemoDialogs
-
- #ifndef __USTRUCTUREINSPECTORS__
- #include "UStructureInspectors.h"
- #endif
-
- // MacApp
-
- #ifndef __UCONTROL__
- #include "UControl.h"
- #endif
-
- #ifndef __UDRAWINGENVIRONMENT__
- #include "UDrawingEnvironment.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UKEYSELECTIONBEHAVIOR__
- #include "UKeySelectionBehavior.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPOPUP__
- #include "UPopup.h"
- #endif
-
- #ifndef __UPRINTING__
- #include "UPrinting.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __UTABBEHAVIORS__
- #include "UTabBehaviors.h"
- #endif
-
- #ifndef __UTEVIEW__
- #include "UTEView.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __FP__
- #include <fp.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
-
- //----------------------------------------------------------------------------------------
- // Constants
-
- const short kMaxPlaces = 13;
-
- const short mUpArrow = 100;
- const short mDownArrow = 101;
- const short mTemperatureChanged = 102;
-
- //========================================================================================
- // CLASS TSwallowBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TSwallowBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSwallowBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSwallowBehavior::~TSwallowBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSwallowBehavior::DoToolboxEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TSwallowBehavior::DoToolboxEvent(TToolboxEvent* event)
- {
- if (event && (event->fIdentifier == mouseDown) && event->IsOptionKeyPressed())
- {
- gApplication->Beep(1);
- return TRUE; // consume the event
- }
- else
- return Inherited::DoToolboxEvent(event);
- } // TSwallowBehavior::DoToolboxEvent
-
-
-
-
- //========================================================================================
- // CLASS TChangeBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TChangeBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TChangeBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TChangeBehavior::~TChangeBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TChangeBehavior::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TChangeBehavior::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)// override
- {
- fOwner->Changed(eventNumber, event);
- Inherited::DoEvent(eventNumber, source, event);
- } // TChangeBehavior::DoEvent
-
-
-
- //========================================================================================
- // CLASS TUpdateBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TBehavior
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TUpdateBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TUpdateBehavior destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TUpdateBehavior::~TUpdateBehavior()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TUpdateBehavior::DoBehaviorUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TUpdateBehavior::DoBehaviorUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace) // override
- {
- if (((theChange == mVScrollBarHit) || (theChange == mHScrollBarHit)) && (changedObject != fOwner))
- {
- ((TScrollBar *)(fOwner))->SetLongVal(-((TScrollBar *)(changedObject))->GetLongVal(), kRedraw);
- }
- else
- Inherited::DoBehaviorUpdate(theChange, changedObject, changedBy, dependencySpace);
- } // TUpdateBehavior::DoBehaviorUpdate
-
-
- //========================================================================================
- // CLASS TArrowsControl
- //========================================================================================
- #undef Inherited
- #define Inherited TPicture
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TArrowsControl, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TArrowsControl constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TArrowsControl::TArrowsControl()
- {
- fLastChange = 0;
- } // TArrowsControl::TArrowsControl
-
- //----------------------------------------------------------------------------------------
- // TArrowsControl destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TArrowsControl::~TArrowsControl()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TArrowsControl::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TArrowsControl::TrackMouse(TrackPhase aTrackPhase,
- VPoint& /*anchorPoint*/,
- VPoint& /*previousPoint*/,
- VPoint& nextPoint,
- Boolean /*mouseDidMove*/)// override
- {
- if (TickCount() >= fLastChange + 5)
- {
- fLastChange = TickCount();
- if (aTrackPhase == trackBegin)
- fLastChange = fLastChange + 10;
-
- if (ContainsMouse(nextPoint))
- if (nextPoint.v <= fSize.v / 2)
- this->HandleEvent(mUpArrow, this, NULL);
- else
- this->HandleEvent(mDownArrow, this, NULL);
- }
- } // TArrowsControl::TrackMouse
-
-
- //========================================================================================
- // CLASS TTemperatureCluster
- //========================================================================================
- #undef Inherited
- #define Inherited TCluster
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TTemperatureCluster, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTemperatureCluster destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTemperatureCluster::~TTemperatureCluster()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTemperatureCluster::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TTemperatureCluster::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)// override
- {
- TNumberText * theNumberText;
- long theNumber;
-
-
- switch (eventNumber)
- {
- case mUpArrow:
- case mDownArrow:
- {
- theNumberText = (TNumberText *)(FindSubView('Numb'));
- theNumber = theNumberText->GetValue();
- if (eventNumber == mUpArrow)
- theNumber = theNumber + 1;
- else
- theNumber = theNumber - 1;
- theNumberText->SetValue(theNumber, kRedraw);
-
- this->HandleEvent(mTemperatureChanged, this, NULL);
- break;
- }
- default:
- Inherited::DoEvent(eventNumber, source, event);
- } //switch
- } // TTemperatureCluster::DoEvent
-
- //----------------------------------------------------------------------------------------
- // TTemperatureCluster::GetValue:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- long TTemperatureCluster::GetValue()
- {
- TNumberText * numberText;
-
- numberText = (TNumberText *)this->FindSubView('Numb');
- return (numberText->GetValue());
- } // TTemperatureCluster::GetValue
-
- //----------------------------------------------------------------------------------------
- // TTemperatureCluster::SetValue:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TTemperatureCluster::SetValue(long newValue,
- Boolean redraw)
- {
- TNumberText * numberText;
-
- numberText = (TNumberText *)this->FindSubView('Numb');
- numberText->SetValue(newValue, redraw);
- } // TTemperatureCluster::SetValue
-
-
- //========================================================================================
- // CLASS TTemperatureConversionCluster
- //========================================================================================
- #undef Inherited
- #define Inherited TCluster
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TTemperatureConversionCluster, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTemperatureConversionCluster destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTemperatureConversionCluster::~TTemperatureConversionCluster()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTemperatureConversionCluster::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TTemperatureConversionCluster::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)
- {
- TTemperatureCluster * Celsius;
- TTemperatureCluster * Fahrenheit;
-
- if (eventNumber == mTemperatureChanged)
- {
- Celsius = (TTemperatureCluster *)(this->FindSubView('Cels'));
- Fahrenheit = (TTemperatureCluster *)(this->FindSubView('Fahr'));
- if (source == Celsius)
- {
- Fahrenheit->SetValue(Celsius->GetValue() * 1.8 + 32, kRedraw);
- }
- else if (source == Fahrenheit)
- {
- Celsius->SetValue((Fahrenheit->GetValue() - 32) / 1.8, kRedraw);
- }
- }
- else
- Inherited::DoEvent(eventNumber, source, event);
- } // TTemperatureConversionCluster::DoEvent
-
-
- //========================================================================================
- // CLASS TSlider
- //========================================================================================
- #undef Inherited
- #define Inherited TPicture
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TSlider, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSlider constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TSlider::TSlider()
- {
- fValue = 0;
- fKnobPicture = NULL;
- fKnobRect = CRect(0, 0, 0, 0);
- fMinTop = 0;
- fMaxTop = 0;
- } // TSlider::TSlider
-
- //----------------------------------------------------------------------------------------
- // TSlider destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSlider::~TSlider()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSlider::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TSlider::DoPostCreate(TDocument* itsDocument)// override
- {
- PicHandle knobPicture;
- VRect knobRect;
- CRect tmpR;
-
-
- Inherited::DoPostCreate(itsDocument);
-
- knobPicture = GetPicture(1002);
- fKnobPicture = knobPicture;
- tmpR = (*knobPicture)->picFrame;
- knobRect.left = fSize.h - (tmpR.right - tmpR.left);
- knobRect.top = fSize.v - 16;
- knobRect.right = knobRect.left + tmpR.right - tmpR.left;
- knobRect.bottom = knobRect.top + tmpR.bottom - tmpR.top;
-
- fKnobRect = knobRect.ToRect();
- fMinTop = fKnobRect.top - 84;
- fMaxTop = fKnobRect.top;
- } // TSlider::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TSlider::ContainsMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TSlider::ContainsMouse(const VPoint& theMouse)// override
- {
- CRect knobRect;
-
- GetKnobRect(knobRect);
- return PtInRect(VPtToPt(theMouse), knobRect);
- } // TSlider::ContainsMouse
-
- //----------------------------------------------------------------------------------------
- // TSlider::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TSlider::Draw(const VRect& area)// override
- {
- Inherited::Draw(area); // This draws everything but the knob
- DrawKnob();
- } // TSlider::Draw
-
- //----------------------------------------------------------------------------------------
- // TSlider::DrawKnob:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TSlider::DrawKnob()
- {
- CRect knobRect;
-
- GetKnobRect(knobRect);
- LoadResource(Handle(fKnobPicture)); // In case it was purged from memory
- DrawPicture(fKnobPicture, knobRect);
- } // TSlider::DrawKnob
-
- //----------------------------------------------------------------------------------------
- // TSlider::GetKnobRect:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TSlider::GetKnobRect(CRect& knobRect)
- {
- knobRect = fKnobRect;
- OffsetRect(knobRect, 0, -(fValue * 12));
- } // TSlider::GetKnobRect
-
- //----------------------------------------------------------------------------------------
- // TSlider::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TSlider::TrackMouse(TrackPhase aTrackPhase,
- VPoint& anchorPoint,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean /*mouseDidMove*/)// override
- {
- CRect oldRect;
- CRect newRect;
- CRect difference;
- RgnHandle savedClip;
- short base;
- short offset;
-
-
- GetKnobRect(oldRect);
- newRect = oldRect;
-
- // Compute rectangle of knob's current position
- offset = (short)Min(Max(previousPoint.v - anchorPoint.v, fMinTop - newRect.top), fMaxTop - newRect.top);
- OffsetRect(oldRect, 0, offset);
-
- // Compute rectangle of knob's new position
- offset = (short)Min(Max(nextPoint.v - anchorPoint.v, fMinTop - newRect.top), fMaxTop - newRect.top);
- OffsetRect(newRect, 0, offset);
-
- // If the mouse was released, pin the knob to a value and set slider's value
- if (aTrackPhase == trackEnd)
- {
- base = ((short)(fSize.v - 16 - newRect.top));
- offset = base - ((base + 6) / 12 * 12);
- OffsetRect(newRect, 0, offset);
- fValue = ((short)(fSize.v - 16 - newRect.top) / 12);
- }
-
- // To redraw minimal amount, compute difference between old and new positions
- difference = oldRect;
- if (oldRect.top > newRect.top)
- difference.top = Max(oldRect.top, newRect.bottom);
- else
- difference.bottom = Min(oldRect.bottom, newRect.top);
-
- savedClip = MakeNewRgn();
- GetClip(savedClip);
-
- ClipRect(difference);
- Inherited::Draw(QDToViewRect(difference));
-
- SetClip(savedClip);
- DisposeRgn(savedClip);
-
- LoadResource(Handle(fKnobPicture)); // In case it was purged from memory
- DrawPicture(fKnobPicture, newRect);
- } // TSlider::TrackMouse
-
-
-
- //========================================================================================
- // CLASS TSumStaticText
- //========================================================================================
- #undef Inherited
- #define Inherited TStaticText
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TSumStaticText, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSumStaticText destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSumStaticText::~TSumStaticText()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSumStaticText::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TSumStaticText::Draw(const VRect& area)// override
-
- {
- // Make sure the gray background gets completely erased
- //InsetRect(theRect, fPenSize.h, fPenSize.v);
- EraseRect(&GetQDExtent());
-
- Inherited::Draw(area);
- } // TSumStaticText::Draw
-
-
- //========================================================================================
- // CLASS TCalcDialog
- //========================================================================================
- #undef Inherited
- #define Inherited TPicture
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TCalcDialog, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TCalcDialog::~TCalcDialog()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCalcDialog::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)
- {
- IDType origID;
- char keyHit;
-
- // dcs - 3.0 fix : Bad News. its either this or a mess of FindSubView calls..
- // Can we count on source being a view at this call.. Hmmm..
- // origID = source->fIdentifier;
- origID = ((TView *)source)->fIdentifier;
- keyHit = (char) (origID & 0xFF); // strip all but the last letter of the ID, which
- // we've assigned to the name of the key
- switch (eventNumber)
- {
- case mOKHit: /*??? Should be mControlHit*/
- switch (keyHit)
- {
- case 'C':
- ClearSum();
- break;
- case '=':
- case 'E':
- TotalSum(noOperator);
- break;
- case '/':
- TotalSum(divOperator);
- break;
- case '*':
- TotalSum(mulOperator);
- break;
- case '-':
- TotalSum(subOperator);
- break;
- case '+':
- TotalSum(addOperator);
- break;
- default:
- NewDigit(keyHit);
- break;
- }
- break;
-
- default:
- Inherited::DoEvent(eventNumber, source, event);
- break;
- }
- } // TCalcDialog::DoEvent
-
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::DoKeyEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCalcDialog::DoKeyEvent(TToolboxEvent* event)// override
- {
- Boolean invalidKeyStroke = FALSE;
-
- // Determine the ID to find the view which will be used as the originator of the keystroke
- IDType theID;
- if (event->fKeyCode == kClearVirtualCode)
- theID = 'keyC';
- else
- {
- if (event->fText == '0'
- || event->fText == '1'
- || event->fText == '2'
- || event->fText == '3'
- || event->fText == '4'
- || event->fText == '5'
- || event->fText == '6'
- || event->fText == '7'
- || event->fText == '8'
- || event->fText == '9'
- || event->fText == '.'
- || event->fText == '+'
- || event->fText == '*'
- || event->fText == '/'
- || event->fText == '='
- || event->fText == '1')
- theID = 'key ' | event->fText[1];
- else if (event->fText == chEnter || event->fText == chReturn)
- theID = 'keyE';
- else
- invalidKeyStroke = TRUE;
- }
-
- if (!invalidKeyStroke)
- {
- TView * theView = FindSubView(theID);
- if (theView != NULL)
- ((TControl *)(theView))->Flash();
- this->HandleEvent(mOKHit, theView, NULL);
- }
- else
- SysBeep(1);
- } // TCalcDialog::DoKeyEvent
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::ClearSum:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCalcDialog::ClearSum()
- {
- fArgument = 0;
- fSum = 0;
- fOperator = noOperator;
- fDecimalPoint = FALSE;
- fRestart = TRUE;
- ((TStaticText *)(FindSubView('SUMM')))->SetText("0", TRUE);
- } // TCalcDialog::ClearSum
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::FetchValue:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- double TCalcDialog::FetchValue()
- {
- CStr255 theStr;
-
- ((TStaticText *)FindSubView('SUMM'))->GetText(theStr);
- return atof((const char*)theStr);
- } // TCalcDialog::FetchValue
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::SetValue:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCalcDialog::SetValue()
- {
- CStr255 theStr;
- double aDouble;
- char aCString[255];
- double orderOfMagnitude;
-
-
- aDouble = fSum;
- orderOfMagnitude = log2(fabs(aDouble)) / log2(10); // this says how many digits are
- // left of the decimal point
- if ((orderOfMagnitude > kMaxPlaces - 1) || (orderOfMagnitude < -6))
- {
- short mantissaLength;
-
- orderOfMagnitude = log2(fabs(orderOfMagnitude)) / log2(10);// find the order of the exponent
- if (orderOfMagnitude > 2)
- mantissaLength = kMaxPlaces - 9;
- else
- mantissaLength = kMaxPlaces - 7;
-
- sprintf(aCString, "%.*e", mantissaLength, aDouble); // use floating point conversion
- theStr = aCString;
- }
- else
- {
- sprintf(aCString, "%.*f", kMaxPlaces - 1, aDouble);
- theStr = aCString;
- this->Truncate(theStr); // strip insignificant zeros / decimal point
-
- // now we must make sure it fits in the space in the dialog, which we know to be
- // kMaxPlaces wide (aren't fixed width fonts great?). If the number is still too
- // large, we can just chop off what's off the end, because we know that the most
- // significant part of the number will still be correctly represented.
- if (theStr.Length() > kMaxPlaces)
- theStr.Delete(kMaxPlaces, theStr.Length() - kMaxPlaces);
- }
- ((TStaticText *)(FindSubView('SUMM')))->SetText(theStr, TRUE);
- } // TCalcDialog::SetValue
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::Truncate:
- //----------------------------------------------------------------------------------------
- void TCalcDialog::Truncate(CStr255& theStr)
- {
- short thePos;
-
- thePos = theStr.Length();
- while (theStr[thePos] == '0')
- --thePos; // strip off 0s right of the decimal point
- if (theStr[thePos] == '.') // there is no fractional part so
- --thePos; // also strip the decimal point.
-
- if (thePos != theStr.Length()) // if we've decided to cut something
- {
- if (thePos == 0)
- {
- theStr = "0"; // if everything has been stripped, we know the value is 0.
- }
- else
- {
- theStr.Delete(thePos + 1, theStr.Length() - thePos); // cut it.
- }
- }
- } // TCalcDialog::Truncate
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::TotalSum:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCalcDialog::TotalSum(CalcOperator newOperator)
- {
- fArgument = FetchValue();
- switch (fOperator)
- {
- case noOperator:
- fSum = fArgument;
- break;
- case divOperator:
- fSum = fSum / fArgument;
- break;
- case mulOperator:
- fSum = fSum * fArgument;
- break;
- case subOperator:
- fSum = fSum - fArgument;
- break;
- case addOperator:
- fSum = fSum + fArgument;
- break;
- }
- SetValue();
- fRestart = TRUE;
- fArgument = fSum;
- fOperator = newOperator;
- } // TCalcDialog::TotalSum
-
- //----------------------------------------------------------------------------------------
- // TCalcDialog::NewDigit:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TCalcDialog::NewDigit(char theNumber)
-
- {
- TStaticText * theText = (TStaticText *)(FindSubView('SUMM'));
- CStr255 theStr;
- if (!fRestart)
- theText->GetText(theStr);
-
- if (theStr.Length() < kMaxPlaces - 1) // is there room for another digit?
- {
- fRestart = FALSE;
- if ((theNumber == '.') &&!fDecimalPoint)
- fDecimalPoint = TRUE;
- theStr += theNumber; // append the char onto the end
- theText->SetText(theStr, TRUE);
- }
- } // TCalcDialog::NewDigit
-
-
- //========================================================================================
- // CLASS TAdornmentDemo
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TAdornmentDemo, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TAdornmentDemo constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TAdornmentDemo::TAdornmentDemo()
- {
- fTestView = NULL;
- } // TAdornmentDemo::Initialize
-
- //----------------------------------------------------------------------------------------
- // TAdornmentDemo destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TAdornmentDemo::~TAdornmentDemo()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TAdornmentDemo::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TAdornmentDemo::DoPostCreate(TDocument* itsDocument)
- {
- Inherited::DoPostCreate(itsDocument);
-
- fTestView = this->FindSubView('test');
- } // TAdornmentDemo::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TAdornmentDemo::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TAdornmentDemo::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)// override
- {
- TView * whichView;
- AdornPriority priority;
-
- // Each adorner has the same class signature and ID as the ID of the corresponding checkbox
- if (eventNumber == mCheckBoxHit)
- {
-
- if (source->fIdentifier == 'gray')
- {
- priority = kAdornFirst;
- whichView = this;
- }
- else if (source->fIdentifier == 'fram')
- {
- priority = kAdornLast; // lower than the embossed frame adorner
- whichView = fTestView;
- }
- else
- {
- priority = kAdornAfter;
- whichView = fTestView;
- }
-
- if (((TCheckBox *)(source))->IsOn())
- whichView->AddAdorner(NewStdAdorner(source->fIdentifier, gEmptyString, source->fIdentifier, kFreeOnDeletion), priority, kRedraw);
- else
- whichView->DeleteAdornerByID(source->fIdentifier, kRedraw);
-
- }
- else
- Inherited::DoEvent(eventNumber, source, event);
- } // TAdornmentDemo::DoEvent
-
-
- //========================================================================================
- // CLASS TEmbossedFrame
- //========================================================================================
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TEmbossedFrame, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TEmbossedFrame destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TEmbossedFrame::~TEmbossedFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TEmbossedFrame::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TEmbossedFrame::Draw(TView* itsView,
- const VRect& /*area*/)// override
- {
- CRGBColor saveColor;
- VRect adornArea;
- CRect tempRect;
- CRGBColor anRGBGray;
- RgnHandle outerRgn;
- RgnHandle innerRgn;
-
-
- PenNormal();
-
- itsView->GetAdornExtent(adornArea);
- CRect QDArea(itsView->ViewToQDRect(adornArea));
- tempRect = QDArea;
-
- // • Build the region to use for filling, first create the outer region
- InsetRect(QDArea, 1, 1);
- outerRgn = NewRgn();
- RectRgn(outerRgn, QDArea);
-
- // • Create the inner region
- InsetRect(QDArea, 6, 6);
- innerRgn = NewRgn();
- RectRgn(innerRgn, QDArea);
-
- // • Finally subtract the inner from the outer region
- DiffRgn(outerRgn, innerRgn, outerRgn);
-
- // • Get rid of the inner region
- DisposeRgn(innerRgn);
-
- // • Set the foreground color to the global face color, this allows the user to
- // change the color of the face
- SetIfColor(gRGBLtGray);
- PaintRgn(outerRgn);
-
- // • Get rid of the outer region
- DisposeRgn(outerRgn);
-
- // • Draw the inside black frame
- SetIfColor(gRGBBlack);
- InsetRect(QDArea, 1, 1);
- FrameRect(&QDArea);
-
- // • Draw the shadows
- // THIS WAS "WITH tempRect"
- {
- // • Draw the outer gray shadow
- SetIfColor(gRGBGray);
- MoveTo(tempRect.left + 1, tempRect.bottom - 1); //(h, v)
- LineToPt(tempRect[botRight] - CPoint(1, 1)); //(h, v)
- LineTo(tempRect.right - 1, tempRect.top + 1); //(h, v)
-
- // • Draw the inner gray shadow
- SetIfColor(gRGBGray);
- MoveTo(tempRect.left + 7, tempRect.bottom - 8); //(h, v)
- LineToPt(tempRect[topLeft] + CPoint(7, 7)); //(h, v)
- LineTo(tempRect.right - 8, tempRect.top + 7); //(h, v)
- }
-
- // • Restore the drawing environment
- itsView->SetupDrawingEnvironment();
- } // TEmbossedFrame::Draw
-
-
- //========================================================================================
- // CLASS TGrayFill
- //========================================================================================
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TGrayFill, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TGrayFill destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TGrayFill::~TGrayFill()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TGrayFill::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TGrayFill::Draw(TView* itsView,
- const VRect& /*area*/)// override
- {
- CRGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
- CRect QDArea;
-
-
- // • Save off the current pen state and the foreground color
- GetPenState(&savePenState);
- GetIfColor(saveColor);
- PenNormal();
-
- itsView->GetAdornExtent(adornArea);
- itsView->ViewToQDRect(adornArea, QDArea);
-
- SetIfColor(gRGBGray);
- PaintRect(QDArea);
-
- // • Restore the foreground color and the pen
- SetIfColor(saveColor);
- SetPenState(&savePenState);
- } // TGrayFill::Draw
-
-
- //========================================================================================
- // CLASS TEtchedFrame
- //========================================================================================
- #undef Inherited
- #define Inherited TAdorner
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TEtchedFrame, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TEtchedFrame constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TEtchedFrame::TEtchedFrame()
- {
- fInset.h = 1;
- fInset.v = 1;
- } // TEtchedFrame::TEtchedFrame
-
- //----------------------------------------------------------------------------------------
- // TEtchedFrame destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TEtchedFrame::~TEtchedFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TEtchedFrame::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TEtchedFrame::Draw(TView* itsView,
- const VRect& /*area*/) // override
- {
- CRGBColor saveColor;
- PenState savePenState;
- VRect adornArea;
-
-
- // • Save off the current pen state and the foreground color
- GetPenState(&savePenState);
- GetIfColor(saveColor);
- PenNormal();
-
- itsView->GetAdornExtent(adornArea);
- CRect QDArea(itsView->ViewToQDRect(adornArea));
-
- SetIfColor(gRGBBlack);
- InsetRect(QDArea, fInset.h, fInset.v);
- FrameRect(QDArea); // Draw the shadows
-
- OffsetRect(QDArea, 1, 1);
- SetIfColor(gRGBWhite);
- FrameRect(QDArea); // Draw the light edges
-
- OffsetRect(QDArea, -1, -1);
- SetCPixel(QDArea.left, QDArea.bottom, gRGBBlack); // Finish the corners
- SetCPixel(QDArea.right, QDArea.top, gRGBBlack);
-
- // • Restore the foreground color and the pen
- SetIfColor(saveColor);
- SetPenState(&savePenState);
- } // TEtchedFrame::Draw
-
-
- //========================================================================================
- // CLASS TSlowScroller
- //========================================================================================
- #undef Inherited
- #define Inherited TScroller
-
- #pragma segment ARes
- MA_DEFINE_CLASS_M1(TSlowScroller, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSlowScroller constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TSlowScroller::TSlowScroller()
- {
- } // TSlowScroller::TSlowScroller
-
- //----------------------------------------------------------------------------------------
- // TSlowScroller destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSlowScroller::~TSlowScroller()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSlowScroller::ScrollStep:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- VCoordinate TSlowScroller::ScrollStep(VHSelect vhs, short partCode) // override
- {
- VCoordinate scrollUnit = fScrollUnit[vhs];
- if (IsControlKeyDown())
- scrollUnit = 1;
- VCoordinate delta;
-
- switch (partCode)
- {
- case kControlUpButtonPart:
- case kControlDownButtonPart:
- delta = scrollUnit;
- break;
-
- case kControlPageUpPart:
- case kControlPageDownPart:
- if (IsControlKeyDown())
- delta = 1;
- else
- delta = fSize[vhs] - scrollUnit;
- break;
-
- #if qDebug
- default:
- {
- CStr255 theString;
- ConcatNumber("TScroller::ScrollStep: bad part code =", partCode, theString);
- ProgramBreak(theString);
- }
- break;
- #endif
-
- }
-
- if ((partCode == kControlUpButtonPart) || (partCode == kControlPageUpPart))
- delta = -delta;
-
- // Constrain if necessary
- if (fConstrain[vhs] && (scrollUnit != 0))
- {
- VCoordinate adjustment = (Max(0, fTranslation[vhs] + delta)) % scrollUnit;
- if (adjustment != 0)
- if (delta > 0)
- delta -= adjustment;
- else
- delta += (scrollUnit - adjustment);
- }
-
- VPoint deltaPt(0, 0);
- deltaPt[vhs] = delta;
-
- this->DoScroll(deltaPt, kRedraw);
- return delta;
- } // TSlowScroller::Draw
-
- //----------------------------------------------------------------------------------------
- // End of UDemoDialogs.More.cp
-
- #pragma segment Inline
-